<%--
  Created by IntelliJ IDEA.
  User: 22240
  Date: 2022/5/18
  Time: 10:16
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <script src="https://apps.bdimg.com/libs/jquery/2.1.4/jquery.min.js"></script>
    <title>Title</title>
</head>
<body>
    <font color="#ffc0cb" size="6">用户注册界面</font><br>
    用户名: <input type="text" name="username" id="username"/><br>
    <span id="sp"></span><br>
    密码: <input type="password" name="pwd" id="pwd"/><br>
    <input type="button" value="注册"/>
    <script type="text/javascript">
        $(function(){
            $("[type='button']").click(function(){
                var username = $("#username").val();
                if(username != null && username != "") {
                    $.post("${pageContext.request.contextPath}/registServlet", {
                        name: username
                    }, function(result){
                        if (result == "1") {
                            var htmlStr = "<font color='green'>恭喜您可以注册!</font>";
                            $("#sp").html(htmlStr);
                        } else {
                            var htmlStr = "<font color='red'>不好意思, 该用户已存在!</font>";
                            $("#sp").html(htmlStr);
                        }
                    });
                }
            });
        });
    </script>
</body>
</html>
